fix: Faker::Config.lazy_loading configuration must be respected (WIP)#3256
Draft
fix: Faker::Config.lazy_loading configuration must be respected (WIP)#3256
Faker::Config.lazy_loading configuration must be respected (WIP)#3256Conversation
This fix initializes lazy loading or eager loading after the first time a generator is called, which can be a bit surprising. But this guarantees that the `Faker::Config.lazy_loading` setting is respected.
thdaraujo
commented
May 1, 2026
| end.join('/') | ||
| end | ||
|
|
||
| # TODO: refactor this |
Contributor
Author
There was a problem hiding this comment.
maybe we can move this out to a lazy loading class or module
Contributor
Author
|
testing script require_relative "lib/faker"
lazy_loading = if ENV.key?('FAKER_LAZY_LOAD')
puts 'set via env...'
ENV['FAKER_LAZY_LOAD'] == '1'
else
puts 'set via config...'
Faker::Config.lazy_loading = false # true
end
puts "Number of constants: #{Faker.constants.size}"
puts "Faker::Name #{Faker::Name.name}"
puts "Number of constants: #{Faker.constants.size}"
if lazy_loading
puts "faker is lazy loading..."
if Faker.constants.size > 10
raise "must be lazy loaded!"
else
"lazy loading success!"
end
else
puts "faker is NOT lazy loading..."
if Faker.constants.size < 10
raise "must be eager loaded!"
else
"eager loading success!"
end
end |
810d21a to
336ca2e
Compare
Fix this failure when lazy loading: https://github.com/faker-ruby/faker/actions/runs/25201119276/job/73892235147?pr=3256
f6c2113 to
471afd9
Compare
thdaraujo
commented
May 1, 2026
| private_constant :EAGER_LOAD_MUTEX | ||
|
|
||
| # initial usage determines lazy loading or eager loading | ||
| # TODO: this can be a bit surprising and error-prone |
Contributor
Author
There was a problem hiding this comment.
this sets up loading the first time a generator is called, which could be a bit surprising/unexpected.
maybe it's a good enough solution for letting folks test it?
in the future, we aim to make lazy loading default, so this wouldn't be a problem anymore, in my view.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(fixes #3248 )
(This is work in progress)
This fix initializes lazy loading or eager loading after the first time a generator is called, which can be a bit surprising.
But this guarantees that the
Faker::Config.lazy_loadingsetting is respected.Motivation / Background
This Pull Request has been created because [REPLACE ME].
Additional information
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]If you're proposing a new generator or locale: